package api

import (
	"context"
	"myproject/backend/types"
	"myproject/backend/utils"
)

type HomeApi struct {
	Ctx context.Context
}

func NewHomeApi() *HomeApi {
	return &HomeApi{}
}

// 获取眼镜店首页销售数据统计
func (c *HomeApi) GetGlassStoreShipStatistics(req types.ShipStatisticQueryReq) types.ShipStatisticQueryResp {
	resp := types.ShipStatisticQueryResp{}
	query := map[string]interface{}{}
	if req.TypeId != 0 {
		query["typeId"] = req.TypeId
	}
	if req.GeneralId != 0 {
		query["generalId"] = req.GeneralId
	}
	if req.TimeFlag != 0 {
		query["timeFlag"] = req.TimeFlag
	}
	if req.Name != "" {
		query["name"] = req.Name
	}
	if req.OrganizeId != 0 {
		query["organizeId"] = req.OrganizeId
	}
	err := utils.HttpRequest(utils.HttpRequestOptions{
		Method:      "GET",
		Suffix:      "/bms/glass/saleStatistics",
		Resp:        &resp,
		QueryParams: query,
	})
	if err != nil {
		resp.Code = types.FAIL
		resp.Msg = err.Error()
		return resp
	}
	return resp
}

// 获取眼镜店销售客户分布
func (c *HomeApi) GetGlassStoreShipCustomerDistribution(req types.ShipStatisticQueryReq) types.RankingResp {
	resp := types.RankingResp{}
	query := map[string]interface{}{}
	if req.TypeId != 0 {
		query["typeId"] = req.TypeId
	}
	if req.GeneralId != 0 {
		query["generalId"] = req.GeneralId
	}
	if req.TimeFlag != 0 {
		query["timeFlag"] = req.TimeFlag
	}
	if req.Name != "" {
		query["name"] = req.Name
	}
	if req.OrganizeId != 0 {
		query["organizeId"] = req.OrganizeId
	}
	err := utils.HttpRequest(utils.HttpRequestOptions{
		Method:      "GET",
		Suffix:      "/bms/glass/saleCustomerDistribution",
		Resp:        &resp,
		QueryParams: query,
	})
	if err != nil {
		resp.Code = types.FAIL
		resp.Msg = err.Error()
		return resp
	}
	return resp
}

// 获取眼镜店销售商品分布
func (c *HomeApi) GetGlassStoreShipGoodsDistribution(req types.ShipStatisticQueryReq) types.RankingResp {
	resp := types.RankingResp{}
	query := map[string]interface{}{}
	if req.TypeId != 0 {
		query["typeId"] = req.TypeId
	}
	if req.GeneralId != 0 {
		query["generalId"] = req.GeneralId
	}
	if req.TimeFlag != 0 {
		query["timeFlag"] = req.TimeFlag
	}
	if req.Name != "" {
		query["name"] = req.Name
	}
	if req.OrganizeId != 0 {
		query["organizeId"] = req.OrganizeId
	}
	err := utils.HttpRequest(utils.HttpRequestOptions{
		Method:      "GET",
		Suffix:      "/bms/glass/saleGoodsDistribution",
		Resp:        &resp,
		QueryParams: query,
	})
	if err != nil {
		resp.Code = types.FAIL
		resp.Msg = err.Error()
		return resp
	}
	return resp
}

// 获取眼镜店销售趋势
func (c *HomeApi) GetGlassStoreShipTrend(req types.ShipStatisticQueryReq) types.ShipStatisticQueryResp {
	resp := types.ShipStatisticQueryResp{}
	query := map[string]interface{}{}
	if req.TypeId != 0 {
		query["typeId"] = req.TypeId
	}
	if req.GeneralId != 0 {
		query["generalId"] = req.GeneralId
	}
	if req.TimeFlag != 0 {
		query["timeFlag"] = req.TimeFlag
	}
	if req.Name != "" {
		query["name"] = req.Name
	}
	if req.OrganizeId != 0 {
		query["organizeId"] = req.OrganizeId
	}
	err := utils.HttpRequest(utils.HttpRequestOptions{
		Method:      "GET",
		Suffix:      "/bms/glass/saleTrend",
		Resp:        &resp,
		QueryParams: query,
	})
	if err != nil {
		resp.Code = types.FAIL
		resp.Msg = err.Error()
		return resp
	}
	return resp
}

// 获取检查单二维码
func (c *HomeApi) GetCheckOrderQrCode(organizeId int) types.CustomCheckOrderQrCodeResp {
	resp := types.CustomCheckOrderQrCodeResp{}
	query := map[string]interface{}{}
	if organizeId != 0 {
		query["organizeId"] = organizeId
	}
	err := utils.HttpRequest(utils.HttpRequestOptions{
		Method:      "GET",
		Suffix:      "/bms/custom/checkOrderQrCode",
		Resp:        &resp,
		QueryParams: query,
	})
	if err != nil {
		resp.Code = types.FAIL
		resp.Msg = err.Error()
		return resp
	}
	return resp
}

// 获取代办列表 req types.TodoListReq
func (c *HomeApi) GetTodoList() types.GetTodoTaskResp {
	resp := types.GetTodoTaskResp{}
	err := utils.HttpRequest(utils.HttpRequestOptions{
		Method: "GET",
		Suffix: "/taskcenter/todotask/getTodoTasksList",
		Resp:   &resp,
	})
	if err != nil {
		resp.Code = types.FAIL
		resp.Msg = err.Error()
		return resp
	}
	return resp
}
